/* Copyright (C) 2008 Robin Debreuil -- Released under the BSD License */

using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;

namespace SWF
{
	public class ClipActionRecord 
	{
		public ClipEvents ClipEvents;
		public uint ActionRecordSize;
		public byte KeyCode;
		public ActionRecords ActionRecords;
		
		public ClipActionRecord(SwfReader r) : this(r, true)
		{
		}
		public ClipActionRecord(SwfReader r, bool isSwf6Plus)
		{
			uint highClip = r.GetBits(16) << 16;
			uint lowClip = 0;
			bool isEndRecord = false;
			if (highClip == 0)
			{
				if (isSwf6Plus)
				{
					lowClip = r.GetBits(16);
					if (lowClip == 0)
					{
						ClipEvents = (ClipEvents)0;
						ActionRecordSize = 4;
						isEndRecord = true;
					}
				}
				else
				{
					ClipEvents = (ClipEvents)0;
					ActionRecordSize = 2;
					isEndRecord = true;
				}
			}
			else
			{
				lowClip = r.GetBits(16);
			}

			if (!isEndRecord)
			{
				ClipEvents = (ClipEvents)(lowClip | highClip);
				ActionRecordSize = r.GetUI32();
				if ((ClipEvents & ClipEvents.KeyPress) > 0)
				{
					KeyCode = r.GetByte();
				}
				ActionRecords = new ActionRecords(r, ActionRecordSize); // always is init tag?
			}
		}
	}
}
